<template>
    <div class="index_b">
        <v-header ref="header" @into="goto('mmy')" :isRegister="isRegister"></v-header>
        <div class="indexbox" :style="{height:docHeight}" ref="box">
            <div class="index" v-show="isRegister">
                <div class="index_card" @click="clickQrcode()">
                    <img src="../assets/index1.png" alt="" class="hx_img">
                    <div class="index_title">核销</div>
                </div>
                <div class="index_card" @click="goto('mopencard',)">
                    <img src="../assets/index2.png" alt="" class="hx_img">
                    <div class="index_title">开卡</div>
                </div>
            </div>
            <div v-show="!isRegister" class="hz">{{msg}}</div>
        </div>
        <v-footer title="1" ref="footer" @into="intos()" v-show="isRegister"></v-footer>
    </div>
</template>
<script>
import header from './common/mheader'
import footer from './common/mfooter'
import getUrlParam from '../store/modules/getUrlParam'
import cookie from '../store/modules/cookie'
import wx from 'weixin-js-sdk'
    export default {
        components: {
            'v-header': header,
            'v-footer': footer
        },
        data () {
            return {
                docHeight: '',
                headerHeight:0,
                footerHeight:0,
                success:false,
                isRegister:true,
                msg:''
            }
        },
        mounted () {
            this.headerHeight = this.$refs.header.$refs.headerbox.offsetHeight
            this.footerHeight = this.$refs.footer.$refs.footerbox.offsetHeight
            this.docHeight = (document.documentElement.clientHeight-this.headerHeight-this.footerHeight)+'px'
        },
        created () {
            this.user()
            // this.scan()
        },
        methods: {
            goto(path,merid){
                this.$router.push({
                    path:'/'+path,
                    query:{
                        merid:merid
                    }
                })
            },
            user(){
                // var getCode = getUrlParam.getParam('code');
                let that = this
                // if (getCode) {
                    // let paramcode = getCode
                    this.$http.get('/merchant/index/oath').then((res)=>{
                        if (res.code == -1) {
                            cookie.setCookie('uid',res.url.uid)
                            console.log(res)
                            that.$router.push({
                                path:'/mlogin'
                            })
                        }else if(res.code == 0){
                            cookie.setCookie('uid',res.data.uid)
                            if(res.data.status !=2){
                                that.isRegister = false
                                that.msg = res.msg
                                that.docHeight = (document.documentElement.clientHeight-this.headerHeight-58)+'px'
                            }else{
                                that.isRegister = true
                            }
                        }
                    })
                // } else {
                //     var pageUrl = window.location.href
                //         .replace(/[/]/g, "%2f")
                //         .replace(/[:]/g, "%3a")
                //         .replace(/[#]/g, "%23")
                //         .replace(/[&]/g, "%26")
                //         .replace(/[=]/g, "%3d");
                //         var url = "https://open.weixin.qq.com/connect/oauth2/authorize?appid=" + "wx1b5c6a97e8b6fbbc" + "&redirect_uri=" + pageUrl + "&response_type=code&scope=snsapi_userinfo&state=STATE&connect_redirect=1#wechat_redirect";
                //         window.location.href = url;
                // }
            },
            scan(){
                            
                
            },
            clickQrcode(){
                let that = this
                let url = window.location.href.split('#')[0]
                that.$http.get('merchant/Scanqrcode/index',{url:url}).then((res)=>{
                    if(res.code == 0){
                        wx.config({
                            debug: true,
                            appId: res.data.appId, 
                            timestamp: res.data.timestamp, 
                            nonceStr: res.data.nonceStr, 
                            signature: res.data.signature,
                            jsApiList: ['scanQRCode']
                        });
                        wx.ready(function(){
                            wx.scanQRCode({
                                needResult: 1,
                                scanType: ["qrCode","barCode"],
                                success: function (res) {
                                    that.$messagebox({
                                        title:'提示',
                                        message:'调起成功'
                                    })
                                }
                            });
                        });
                        wx.error(function(res){
                            that.$messagebox('提示' ,'失败');
                        });
                    }else{
                    }
                })                   
            },
            intos(){
                let that = this
                that.$router.push({
                    path:'/mmy'
                })
            }
        }
    }
</script>
<style scoped>
.indexbox{
    padding: 0 61px;
    background: #000;
}
.index{
    background: #fff;
    text-align: center;
    padding: 135px 75px;
    box-sizing: border-box;
}
.hx_img{
    width: 190px;
    height: 190px;
}
.index_card:nth-child(1){
    border-bottom: 1px solid #7A7A7A;
    padding-bottom: 85px;
}
.index_card:nth-child(2){
    padding-top: 93px;
}
.index_title{
    font-size: 74px;
    padding-top:30px;
    color: #000000;
}
.hz{
    color: #fff;
    font-size: 48px;
    text-align: center;
    padding: 100px 0;
}
</style>